#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:7_do_total_size.py
# author:张世航
# datetime:2024/11/9 22:29
# software: PyCharm
"""
this is function  description 
"""
# import module your need

#
# 7 使用python代码统计一个文件夹中所有文件的总大小
import os

def total_size(directory):
    """计算文件夹中所有文件的总大小"""
    total = 0
    for dirpath, dirnames, filenames in os.walk(directory):
        for f in filenames:
            fp = os.path.join(dirpath, f)
            total += os.path.getsize(fp)
    return total

# 使用示例
if __name__ == "__main__":
    directory_path = r"D:\文档\python\zhangshihang——python"  # 使用原始字符串
    total = total_size(directory_path)
    print(f"总大小: {total} bytes")